package com.kunpan.admin;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.util.StringUtils;

import java.net.InetAddress;
import java.net.UnknownHostException;

@EnableTransactionManagement //开启事物管理
@SpringBootApplication
@EnableKnife4j
//开启异步任务
@EnableAsync
public class KunpanApplication {

    public static void main(String[] args) {
//        SpringApplication.run(KunpanApplication.class, args);
        ConfigurableApplicationContext run = SpringApplication.run(KunpanApplication.class, args);
        System.out.println("(♥◠‿◠)ﾉﾞ 有情提示:启动成功   ლ(´ڡ`ლ)ﾞ  \n");
        System.out.println("===========  Knife4j接口文档地址  ===========");
        ConfigurableEnvironment environment = run.getEnvironment();
        //获取项目端口号
        String port = environment.getProperty("server.port");
        //获取项目根路径
        String path = environment.getProperty("server.servlet.context-path");
        if (!StringUtils.hasLength(path) || path.equals("/")) {
            path = "";
        }
        try {
            // 获取项目访问主机名称
            String hostAddress = InetAddress.getLocalHost().getHostAddress();
            //内网访问地址
            System.out.println("内网访问地址:" + "http://" + hostAddress + ":" + port + path + "/doc.html");
            //本地访问地址
            System.out.println("本地访问地址:" + "http://" + "localhost:" + port + path + "/doc.html");
        } catch (UnknownHostException e) {
            throw new RuntimeException(e);
        }
    }
}
